package me.numark.fragments;

import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import me.numark.R;
import me.numark.activities.BaseActivity;
import me.numark.activities.LogInActivity;

/**
 * Created by Evan on 15/7/25.
 */
public class AskLoginFragment extends DialogFragment {

    public static void show(BaseActivity activity) {
        DialogFragment newFragment = new AskLoginFragment();
        newFragment.show(activity.getSupportFragmentManager(), "loginDialog");
    }

    public static void show(Fragment fragment) {
        DialogFragment newFragment = new AskLoginFragment();
        newFragment.show(fragment.getChildFragmentManager(), "loginDialog");
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final Dialog lDialog = new Dialog(getActivity(),R.style.dialog_style);
        lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        lDialog.setContentView(R.layout.r_okcanceldialogview);
        TextView dialogMessage = (TextView) lDialog.findViewById(R.id.dialog_message);
        dialogMessage.setText(getString(R.string.ask_login_dialog_msg));
        ((Button) lDialog.findViewById(R.id.cancel))
                .setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        AskLoginFragment.this.dismiss();
                    }
                });
        ((Button) lDialog.findViewById(R.id.ok))
                .setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        AskLoginFragment.this.dismiss();
                        getActivity().startActivity(new Intent(getActivity(), LogInActivity.class));
                    }
                });
        return lDialog;
    }
}
